<template>
  <div class="update-gender">
    <van-picker
      show-toolbar
      :columns="columns"
      :default-index="localGender"
      @cancel="$emit('close')"
      @confirm="onConfirm"
    />
  </div>
</template>

<script>
import { updateUserProfile } from '@/api/user.js'
export default {
  name: 'UpdateGender',
  props: {
    value: {
      type: Number,
      required: true
    }
  },
  components: {},
  data () {
    return {
      localGender: this.value,
      showPicker: false,
      columns: ['男', '女']
    }
  },
  computed: {},
  watch: {},
  methods: {
    async onConfirm (index) {
      await updateUserProfile({
        gender: index
      })
      this.$toast.success('修改性别成功')
      this.$emit('input', index)
      this.$emit('close')
    }
  },
  created () {
  },
  mounted () {
  },
  destroyed () {
  }
}
</script>

<style scoped lang='less'>
</style>
